package com.etime.shycourse.controller.ad;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shy.common.PojoMessage;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.dto.AdLogDto;
import com.etime.shycourse.dto.AdStatisticDto;
import com.etime.shycourse.services.ad.interfaces.AdStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 广告统计控制层
 */
@Api(tags = "后台-广告统计数据接口")
@RestController
@RequestMapping("/sys/adstatistics")
public class AdStatisticsController {
    @Autowired
    private AdStatisticsService adStatisticsService;

    @ApiOperation("广告统计")
    @GetMapping("/count")
    public PojoMessage<AdStatisticDto> countAdStatistic() {
        PojoMessage<AdStatisticDto> msg = new PojoMessage<>();
        AdStatisticDto adStatisticDto = adStatisticsService.countAdStatistic();
        if (adStatisticDto != null) {
            msg.setData(adStatisticDto);
            msg.setMsg("查询成功");
        } else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }
    @ApiOperation("查询广告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据")
    })
    @GetMapping("/adList")
    public PageMessage<AdLogDto> selectAdList(Long pageNum, Long pageSize,Integer adstate){
        PageMessage<AdLogDto> msg = new PageMessage<>();
        Page<AdLogDto> page =adStatisticsService.selectAdList(pageNum,pageSize,adstate);
        if(page!=null){
            msg.setPagedata(page);
            msg.setMsg("查询成功");
            msg.setCode(1);
        }else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }

    @ApiOperation("根据广告id统计广告收益")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "placeid",value = "广告位id"),
            @ApiImplicitParam(name = "pageNum",value = "当前第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据")
    })
    @GetMapping("/revenue")
    public PojoMessage<AdStatisticDto> countAdRevenue(Long placeid) {
        PojoMessage<AdStatisticDto> msg = new PojoMessage<>();
        AdStatisticDto adStatisticDto = adStatisticsService.countAdRevenue(placeid);
        if (adStatisticDto != null) {
            msg.setData(adStatisticDto);
            msg.setMsg("查询成功");
        } else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }
    @ApiOperation("根据广告id和广告状态查询广告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "placeid",value = "广告位id"),
            @ApiImplicitParam(name = "pageNum",value = "当前第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据")
    })
    @GetMapping("/AdplaceList")
    public PageMessage<AdLogDto> selectAdListByPlaceId(Long pageNum, Long pageSize,Integer adstate,Long placeid){
        PageMessage<AdLogDto> msg = new PageMessage<>();
        Page<AdLogDto> page =adStatisticsService.selectAdListByPlaceId(pageNum,pageSize,adstate,placeid);
        if(page!=null){
            msg.setPagedata(page);
            msg.setMsg("查询成功");
            msg.setCode(1);
        }else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }

    @ApiOperation("机构广告统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgid",value = "机构id"),
            @ApiImplicitParam(name = "pageNum",value = "当前第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据")
    })
    @GetMapping("/org")
    public PojoMessage<AdStatisticDto> countOrgAd(Integer orgid) {
        PojoMessage<AdStatisticDto> msg = new PojoMessage<>();
        AdStatisticDto adStatisticDto = adStatisticsService.countOrgAd(orgid);
        if (adStatisticDto != null) {
            msg.setData(adStatisticDto);
            msg.setMsg("查询成功");
        } else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }
    @ApiOperation("根据机构id和广告状态查询广告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgid",value = "机构id"),
            @ApiImplicitParam(name = "pageNum",value = "当前第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据")
    })
    @GetMapping("/OrgAdList")
    public PageMessage<AdLogDto> selectAdListByOrgId(Long pageNum, Long pageSize,Integer adstate,Integer orgid){
        PageMessage<AdLogDto> msg = new PageMessage<>();
        Page<AdLogDto> page =adStatisticsService.selectAdListByOrgId(pageNum,pageSize,adstate,orgid);
        if(page!=null){
            msg.setPagedata(page);
            msg.setMsg("查询成功");
            msg.setCode(1);
        }else {
            msg.setMsg("未查询到数据");
            msg.setCode(0);
        }
        return msg;
    }



}
